TailsConfig.registerFormat({
  name: 'hresume',
  topNodeClass: 'hresume',

  simpleValueClasses: ["summary"],

  customBindings: {
    vcard: function(node, object) {
      if (!object.contact_hcard || node.tagName.toLowerCase() == 'address')
        this.contact(node, object);
    },
    contact: function(node, object) {
      object.contact_hcard = TailsConfig.getFormat('hcard').parseObject(node);
      return true;
    },
    education: function(node, object) {
      if (!object.education) object.education = [];
      object.education.push(TailsConfig.getFormat('hcalendar').parseObject(node));
      return true;
    },
    experience: function(node, object) {
      if (!object.experience) object.experience = [];

      var exp = {};
      if (node.getAttribute("class").match(TailsConfig.getFormat('hcalendar').topNodePattern))
        exp.hcalendar = TailsConfig.getFormat('hcalendar').parseObject(node);

      var format = TailsConfig.getFormat('hcard');
      var vcard = FormatBase.findNodeForFormat(format, node);
      if (vcard) exp.hcard = format.parseObject(vcard);
      object.experience.push(exp);
      return true;
    },
    skill: function(node, object) {
      if (!node.getAttribute("rel") || !node.getAttribute("rel") == "tag")
        return false;
 
      if (!object.skill) object.skill = [];
      object.skill.push(FormatBase.toText(node));
      return true;
    },
    affiliation: function(node, object) {
      if (!object.affiliation) object.affiliation = [];
      object.affiliation.push(TailsConfig.getFormat('hcard').parseObject(node));
      return true;
    }
  },

  _checkNode: function(node, object) {
    if (node.tagName.toLowerCase() == "cite") {
      if (!object.publications) object.publications = [];
      object.publications.push(FormatBase.toText(node));
      return true;
    }
  },

  _getLabel: function(object) {
    return object.contact_hcard.generic.label;
  },
  _getURL: function(object) {
    return object.contact_hcard.generic.url;
  },
  _getDescription: function(object) {
    var s = "";
    if (object.summary) {
      s += object.summary;
    }
    if (object.skill && object.skill.length > 0) {
      s += " " + TailsNS.getMessage("hresume_desc_skills", [object.skill.join(", ")]);
    }
    return s;
  },
  end: null
});
